package com.adong.springboot.listener;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

public class HelloSpringApplicationRunListener implements SpringApplicationRunListener {
    public HelloSpringApplicationRunListener(SpringApplication application, String[] args) {
    }

    @Override
    public void starting() {
        //启动已准备好的监听器，发布应用启动事件
        System.out.println("SpringApplicationRunListener + starting");
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
        //环境准备好了
        Object o = environment.getSystemProperties().get("os.name");
        System.out.println("SpringApplicationRunListener + environmentPrepared" + o);
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        //ioc容器准备好了
        System.out.println("SpringApplicationRunListener + contextPrepared");
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        //容器环境加载完成
        System.out.println("SpringApplicationRunListener + contextLoaded");
    }

    @Override
    public void started(ConfigurableApplicationContext context) {
        //发布应用上下文启动完成事件
        System.out.println("SpringApplicationRunListener + started");
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        //发布应用上下文就绪事件
        System.out.println("SpringApplicationRunListener + running");

    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        //创建完成
        System.out.println("SpringApplicationRunListener + failed");
    }
}
